<?php
namespace app\index\controller;

use Phpml\Classification\KNearestNeighbors;
use Phpml\Association\Apriori;

class Ai extends Base
{
	/**
	 * demo
	 * @Author   zhibin3
	 * @DateTime 2022-11-29
	 * @return   [type]     [description]
	 */
	public function index()
	{
		$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
		$labels = ['a', 'a', 'a', 'b', 'b', 'b'];

		$classifier = new KNearestNeighbors();
		$classifier->train($samples, $labels);

		$result = $classifier->predict([3, 2]);
		dump($result);
		// return 'b'
	}

	/**
	 * [b description]
	 * @Author   zhibin3
	 * @DateTime 2022-11-29
	 * $support - 支持的最小阈值，即规则“如果X然后Y”包含X和Y的样本的比率
	 * $confidence - 最小置信度，即包含X和Y的样本与包含X的样本的比率
	 * @return   [type]     [description]
	 */
	public function b()
	{
		//样品
		$samples = [['2022023', '3', '7', '10', '21', '28', '31'], ['2022024', '3', '7', '10', '21', '28', '31'], ['2022025', '3', '7', '10', '21', '28', '31'], ['2022026', '3', '7', '10', '21', '28', '31']];
		//标签
		$labels  = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31];
		$associator = new Apriori($support = 0.5, $confidence = 0.5);

		//训练
		$associator->train($samples, $labels);

		//预测
		$result_1 = $associator->predict(['3']);
		// $result_2 = $associator->predict([['alpha','epsilon'],['beta','theta']]);

		pre($result_1);
	}
}